import { ref } from 'vue'

export default function useTableFn() {
  const commonRef = ref(null)

  /* 表格属性 */
  const tableProps = ref({
    data: [],
    rowKey: 'id',
    tooltipEffect: 'light',
  })

  /* 分页属性 */
  const pageProps = ref({
    // 当前页数
    currentPage: 1,
    // 总条数
    total: 0,
  })

  /* 查询搜索数据 */
  const searchData = ref({})

  /**
   * 查询列表指定页数
   * @param currentPage 当前页数,默认为1
   */
  const operateSearch = (currentPage=1) => {
    if(pageProps.value?.currentPage != currentPage)  {
      return pageProps.value.currentPage = currentPage
    }
    commonRef.value?.handlePageChange(currentPage)
  }

  // 搜索
  const search = () => {
    operateSearch()
  }

  return {
    commonRef,
    tableProps,
    pageProps,
    searchData,
    search,
    operateSearch
  }
}
